package com.qf.factory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 自定义工厂
 *   清单：
 *     userDao=com.qf.dao.UserDAOImpl
 *     userService=com.qf.service.UserServiceImpl
 * @author lixu
 */
public class MyFactory {

    private static Properties properties = new Properties();

    public MyFactory(String config){
        try {
            InputStream is = MyFactory.class.getResourceAsStream(config);
            properties.load(is);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    /**
     * 让工厂生产吧 Dao Service
     */
    public static Object getBean(String name) throws Exception{
        String value = properties.getProperty(name);
        //包名 + 类名 == 类路径名
        Class<?> aClass = Class.forName(value);
        return aClass.newInstance();
    }



}
